//package com.icangya.common.config;
//
//import com.icangya.DAO.ICommissionFootDAO;
//import com.icangya.DAO.ICommissionRecordDAO;
//import com.icangya.Utils.FormatUtil;
//import com.icangya.domain.*;
//import com.icangya.service.IFbWxSuitcaseService;
//import com.icangya.service.IFootUserService;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.sql.Timestamp;
//import java.util.Date;
//import java.util.List;
//
///**
// * 基于注解的定时器
// * @author hj
// */
//@Component
//public class MyTaskAnnotation {
//
//    private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Autowired
//    private IRedWineGameService iRedWineGameService;
//    @Autowired
//    private IFootUserService iFootUserService;
//    @Autowired
//    private ICommissionFootDAO iCommissionFootDAO;
//    @Autowired
//    private ICommissionRecordDAO iCommissionRecordDAO;
//    @Autowired
//    private IFbWxSuitcaseService iFbWxSuitcaseService;
//
//    /**
//     * 定时计算。每天凌晨 01:00 执行一次
//     * 均分营业额
//     * 商城每天凌晨一点计算前一天的总营业额，拿出百分比（暂定百分之十），均分给每一位购买过红酒的用户，知道用户购买额的两倍。
//     */
//    @Scheduled(cron = "0 0 1 * * *")
//    public void avgTurnover(){
//        Timestamp yesterday = new Timestamp(FormatUtil.getYesterday().getTime());
//        List<FbPayInfo> fbPayInfoList = iRedWineGameService.getFbPayInfoListByDate(yesterday);
//        RwVariable rwVariable = iRedWineGameService.getRwVariableById(1l);
//
//        /**
//         * 计算当天营业总额，并且保存当天总额记录
//         */
//        Double zje = 0.0;
//        for (int i =0 ;i<fbPayInfoList.size();i++){
//            zje = zje + Double.valueOf(fbPayInfoList.get(i).getTotal_fee())/100;
//        }
//        GainRecord gainRecord = new GainRecord();
//        gainRecord.setCreateTime(yesterday);
//        gainRecord.setGainMoney(zje);//当天营业额
//        gainRecord.setExpendMoney(0.0);//当天支出额
//        gainRecord.setRechargeMoney(0.0);
//        iRedWineGameService.saveGainRecord(gainRecord);
//
//        /**
//         * 均分营业额百分比给vip用户
//         */
//        Double avg_zje = zje * 0.01;//被均分的钱数量,10%
//        List<RwShopVip> rwShopVipList =  iRedWineGameService.getVipUser();
//        int userCount = rwShopVipList.size();
//        double yeejf = avg_zje/userCount;
//        for (int i= 0;i<userCount;i++){
//            User user =  iFootUserService.getUserByUid(rwShopVipList.get(i).getId());
//
//            //用户的营业额返佣总额
//            double userAllMoney = 0.0;
//            List commRecordlist = iCommissionRecordDAO.getCommRecordByOpenIdOrCommTypec(user.getId(),2);
//            for (int j =0 ;j<commRecordlist.size();j++){
//                Object[] obj = ((List<Object[]>)commRecordlist).get(j);
//                userAllMoney = userAllMoney + Double.valueOf(obj[3].toString());
//            }
//
//            //用户的购买额总和
//            int buyAllMoney = iFbWxSuitcaseService.selectFbWxSuitcaseServiceByUserid(user.getId());
//
//            //判断返佣总和是否已达购买额的两倍或两倍以上
//            double dds = userAllMoney / Double.valueOf(buyAllMoney);
//            if(dds >= 2){//两倍或两倍以上则停止返佣，逻辑待添加
//                logger.info("用户的返佣总和已达购买额的两倍或两倍以上，停止返佣");
//            }else{
//                //添加用户返佣记录
//                CommissionRecord cr1 = new CommissionRecord();
//                cr1.setCommissionMoney(yeejf);
//                cr1.setCommissionTime(new Timestamp(new Date().getTime()));
//                cr1.setCommissionType("均分营业额感恩回馈");
//                cr1.setCommissionTypec(3);
//                cr1.setOpenId(user.getOpenId());
//                cr1.setUserid(user.getId());
//                cr1.setRemark("均分"+yesterday+"的"+rwVariable.getTurnover()+"营业额");
//                iRedWineGameService.saveCommissionRecord(cr1);
//                //累加用户佣金总额
//                Commission commission= iCommissionFootDAO.selectUserCommis(user.getOpenId());
//                commission.setMoney(commission.getMoney()+yeejf);
//                boolean result= iCommissionFootDAO.update(commission);
//            }
//        }
//
//        /**
//         * 定时计算。每天凌晨 01:00 执行一次
//         * 股份分红营业额
//         * 商城每天凌晨一点计算前一天的总营业额，拿出百分比（暂定百分之十），按照股份分给股东。待写
//         */
//        Double avg_zje1 = zje * 0.01;//被均分的钱数量,10%
//        int zgf = iRedWineGameService.getSharesSum();
//        Double comm = avg_zje1 / zgf;//每股该分多少钱；
//        List<RwShopShares> rwShopSharesList = iRedWineGameService.getHaveSharesUser();
//        for (int i =0 ;i<rwShopSharesList.size();i++){
//            //将用户所占股份分红（comm * rwShopSharesList.get(i).getSharesNum()）累加到用户佣金总额
//            Commission commission= iCommissionFootDAO.selectUserCommis(rwShopSharesList.get(i).getOpenid());
//            commission.setMoney(commission.getMoney() + (comm * rwShopSharesList.get(i).getSharesNum()));
//            boolean result= iCommissionFootDAO.update(commission);
//        }
//
//        logger.info("Annotation：is avgTurnover run");
//    }
//
//
//    /**
//     * 定时计算。每天凌晨 01:00 执行一次
//     */
////    @Scheduled(cron = "0 0 1 * * *")
////    public void show(){
////
////        logger.info("Annotation：is show run");
////    }
//
//    /**
//     * 心跳更新。启动时执行一次，之后每隔2秒执行一次
//     */
////    @Scheduled(fixedRate = 1000*2)
////    public void print(){
////
////        logger.info("Annotation：print run");
////    }
//
//
//}